<template>
	<view class="main">
		<view class="banner">
		</view>
		<view class="home-content">
			<view class="home_title">领取我的学术名片</view>
			<view class="home_form">
				<view class="item">
					<u-input placeholder="请输入" v-model="userInfo.realName">
						<u-text text="姓名" slot="prefix" margin="10px"></u-text>
					</u-input>
				</view>
				<view class="item">
					<u-input placeholder="请输入" v-model="userInfo.position">
						<u-text text="职位" slot="prefix" margin="10px"></u-text>
					</u-input>
				</view>
				<view class="item">
					<u-input placeholder="请输入" v-model="userInfo.unit">
						<u-text text="机构" slot="prefix" margin="10px"></u-text>
					</u-input>
				</view>
				<view class="sub">
					<view class="btn" @click="submit">立即领取</view>
				</view>
			</view>

		</view>

	</view>
</template>

<script>
	import {wxInfoCardAddUser} from '@/api/infoCard.js'
	export default {
		data() {
			return {
				userInfo: {
					realName: "",
					position: "",
					unit: ""
				}
			}
		},
		onLoad() {},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			// this.$refs.uForm.setRules(this.rules)
		},
		methods: {

			submit() {
				if (!this.userInfo.realName) {
					uni.$u.toast('请填写姓名')
					return false;
				}
				if (!this.userInfo.position) {
					uni.$u.toast('请填写职位')
					return false;
				}
				if (!this.userInfo.unit) {
					uni.$u.toast('请填写机构')
					return false;
				}
				wxInfoCardAddUser(this.userInfo).then(res => {
					if (res) {
						uni.$u.toast('领取成功');
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		.banner{
			height: 240px;
			background-image: url("http://www.icloud-plat.com/files/business-card/co.png");
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}
	}
	.home-content {
		background: #fff;
		width: 100vw;
	}

	.home_title {
		text-align: center;
		font-size: 25px;
		font-weight: bold;
		padding-top: 10%;
	}

	.home_form {
		padding: 40px;

		.item {
			margin-top: 15px;
		}

		.sub {
			margin-top: 30px;

			.btn {
				height: 50px;
				background-color: #033B75;
				border-radius: 30px;
				text-align: center;
				line-height: 50px;
				color: #fff;
				font-size: 20px;
			}
		}
	}
</style>